package com.rpframework.website.friendly.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.friendly.dao.IProgressDao;
import com.rpframework.website.friendly.domain.Progress;
import com.rpframework.website.friendly.domain.Progress;
import com.rpframework.website.friendly.util.HConstants;

@Service
public class ProgressService extends BaseService{
	public @Resource IProgressDao iDao;
	public Pager<Progress> getPager(Pager<Progress> pager) {
		long startTime = System.currentTimeMillis();
		List<Progress> list = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}

	public boolean doSaveOrUpdate(Progress t) {
		if(NumberUtils.isValid(t.getId())){
			t.setModifyTime(System.currentTimeMillis() / 1000);
			return iDao.update(t);
		}
		t.setCreateTime(System.currentTimeMillis()/1000);
		return insert(t);
	}
	/**
	 * 修改状态
	 * @param id
	 * @return
	 * @time 2016年3月24日 上午10:02:46
	 */
	public boolean doUpdateState(Integer id) {
		if(NumberUtils.isValid(id)){
			Progress t = iDao.select(id);
			if(t.getState() == HConstants.EntityState.STATE_NORMAL){
				t.setState(HConstants.EntityState.STATE_DISABLE);
			}else{
				t.setState(HConstants.EntityState.STATE_NORMAL);
			}
			return iDao.update(t);
		}
		return false;
	}

	public List<Progress> getByNum(Integer num) {
		return iDao.doByNum(num);
	}
}
